package com.wanxi.service.impl;

import com.wanxi.dto.CuisineDTO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.vo.CuisineVO;
import com.wanxi.dao.CuisineDao;
import com.wanxi.dao.impl.CuisineDaoImpl;
import com.wanxi.entity.CuisineEntity;
import com.wanxi.service.CuisineService;
import com.wanxi.util.Tool;
import org.springframework.beans.BeanUtils;

import java.util.List;

public class CuisineServiceImpl implements CuisineService {
    private CuisineDao cuisineDao = new CuisineDaoImpl();

    @Override
    public ResultDTO add(CuisineVO cuisineVO) {
        return null;
    }

    @Override
    public ResultDTO delete(CuisineVO cuisineVO) {
        return null;
    }

    @Override
    public ResultDTO findById(CuisineVO cuisineVO) {
        return null;
    }

    @Override
    public ResultDTO findAll(CuisineVO cuisineVO) {
        CuisineEntity cuisineEntity = new CuisineEntity();
        BeanUtils.copyProperties(cuisineVO, cuisineEntity);
        List<CuisineEntity> list = cuisineDao.findAll(cuisineEntity);
//        怎么集合Entity转换为DTO？
        List<CuisineDTO> cuisineDTOS = Tool.copy(list, CuisineDTO.class);
        int count = cuisineDao.count(cuisineEntity);
        return ResultDTO.getResult("", count, cuisineDTOS);
    }

    @Override
    public ResultDTO update(CuisineVO cuisineVO) {
        return null;
    }
}
